package com.xd.clap.services.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xd.clap.entity.*;
import com.xd.clap.entity.request.PageParam;
import com.xd.clap.entity.response.Result;
import com.xd.clap.mapper.RateMapper;
import com.xd.clap.services.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class RateServiceImpl implements RateService {
    @Resource
    private RateMapper rm;

    @Override
    public Boolean uploadRate(Rate rate) {
        return rm.insert(rate) > 0;
    }

    @Override
    public Result getRatePage(PageParam pageParam) {
        IPage<Rate> aPage = new Page<>(pageParam.getPage(), pageParam.getPageSize());
        QueryWrapper<Rate> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("create_time");
        queryWrapper.eq("phone", pageParam.getPhone());
        IPage<Rate> adviseIPage = rm.selectPage(aPage, queryWrapper);
        return Result.success(adviseIPage, "查询成功");
    }

}
